/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package ve.com.fitsoft.eicb.encuesta.SB.service.impl;

import java.util.List;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;

import ve.com.fitsoft.eicb.encuesta.SB.model.Encuesta;
import ve.com.fitsoft.eicb.encuesta.SB.model.Pregunta;
import ve.com.fitsoft.eicb.encuesta.SB.service.base.PreguntaLocalServiceBaseImpl;

/**
 * The implementation of the pregunta local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link ve.com.fitsoft.eicb.encuesta.SB.service.PreguntaLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author leo
 * @see ve.com.fitsoft.eicb.encuesta.SB.service.base.PreguntaLocalServiceBaseImpl
 * @see ve.com.fitsoft.eicb.encuesta.SB.service.PreguntaLocalServiceUtil
 */
public class PreguntaLocalServiceImpl extends PreguntaLocalServiceBaseImpl {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never reference this interface directly. Always use {@link ve.com.fitsoft.eicb.encuesta.SB.service.PreguntaLocalServiceUtil} to access the pregunta local service.
	 */
    public Pregunta addPregunta(Pregunta newPregunta, long userId) {
		Pregunta pregunta;
		try {
			pregunta = preguntaPersistence.create(
					counterLocalService.increment(Pregunta.class.getName())
					);
			resourceLocalService.addResources(
					newPregunta.getCompanyId(),
					newPregunta.getGroupId(),
					userId,
					Encuesta.class.getName(),
					pregunta.getPrimaryKey(),
					false,true, true);
			
			pregunta.setIdEncuesta(newPregunta.getIdEncuesta());
			pregunta.setPregunta(newPregunta.getPregunta());
			pregunta.setOpciones(newPregunta.getOpciones());
			pregunta.setTipo(newPregunta.getTipo());
			pregunta.setGroupId(newPregunta.getGroupId());
			pregunta.setCompanyId(newPregunta.getCompanyId());
						
			return preguntaPersistence.update(pregunta, false);			
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (PortalException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
			
	}	
    
    public List<Pregunta> findPreguntasByEncuesta(long idEncuesta, long groupId){
    	try {
			return preguntaPersistence.findByencuesta(groupId, idEncuesta);
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return null;
    }
}